package cn.zane.designPattern.createPatterns.abstractFactoryPatterns.oldCode.redis;

import lombok.extern.slf4j.Slf4j;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;

/**
 * @Author: zane
 * @Date: 2024/12/29
 * @Description: 模拟Redis服务 单机版
 */
@Slf4j
public class RedisUtils {

    private Map<String, String> dataMap = new ConcurrentHashMap<>();

    public String get(String key) {
        log.info("Redis获取数据 key:{}", key);
        return dataMap.get(key);
    }

    public void set(String key, String value) {
        log.info("Redis写入数据 key:{} val:{}", key, value);
        dataMap.put(key, value);
    }

    public void set(String key, String value, long timeout, TimeUnit unit) {
        log.info("Redis写入数据 key:{} val:{} timeout:{} unit:{}", key, value, timeout, unit);
        dataMap.put(key, value);
    }

    public void del(String key) {
        log.info("Redis删除数据 key:{}", key);
        dataMap.remove(key);
    }
}
